#!/usr/bin/env python
import sys
import commands
from optparse import OptionParser
def check( url, contain_text):
    command = '/usr/bin/curl --connect-timeout 20 %s' % (url)
    try:
        status, output = commands.getstatusoutput(command)
        if status != 0 or contain_text not in output:
            return False
        else:
            return True
    except Exception as e:
        print e
        return False
def main():
    parser = OptionParser(usage = '%prog [options]')
    parser.add_option('-u', '--url', default = 'http://www.baidu.com')
    parser.add_option('-c', '--contain-text', default = 'baidu')
    options, args = parser.parse_args()
    if check(options.url, options.contain_text):
        print 'Okey'
        return 0
    else:
        print 'Not okey'
        return 2
if __name__ == '__main__':
    sys.exit(main())
